#include <vector>
using namespace std;

class Solution
{
public:
    int minSubArrayLen(int target, vector<int> &nums)
    {
        int start = 0, end = 0;
        int len = nums.size();
        int ret = len + 1;
        int sum = 0;
        while (end < len)
        {
            sum += nums[end];
            while (sum >= target)
            {
                ret = min(ret, end - start + 1);
                sum -= nums[start];
                ++start;
            }
            end++;
        }

        return ret == len + 1 ? 0 : ret;
    }
};